package DynamicProxy;

import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;
import java.lang.reflect.Proxy;

public class ProxyClient {
    public static void main(String[] args) {
        Message message = new RespnnseMessage();
        InvocationHandlerTest invocationHandlerTest = new InvocationHandlerTest(message);

        Message message1 = (Message) Proxy.newProxyInstance(invocationHandlerTest.getClass().getClassLoader(), message.getClass().getInterfaces(), invocationHandlerTest);
        System.out.println(message.getClass());
        Proxy.newProxyInstance(invocationHandlerTest.getClass().getClassLoader(), message.getClass().getInterfaces(), invocationHandlerTest);
        message1.hello("你好");
        message1.bye();

        byte[] classByte = ProxyGenerator.generateProxyClass("$Proxy0",
                new Class<?>[] { Message.class });
        String path = "D:\\testdata\\$Proxy0.class";
        try (FileOutputStream fos = new FileOutputStream(path)) {
            fos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
